<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="example.model.User" %>
<html>
<head>
    <title>用户列表</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
</head>
<body>
    <h1>用户列表</h1>
    <form action="userList" method="get">
        <div class="form-group">
            <input type="text" class="form-control" name="query" placeholder="请输入用户名进行查询" value="${query}">
            <button type="submit" class="btn btn-primary">查询</button>
        </div>
    </form>
    <table border="1" class="table table-striped">
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>密码</th>
        </tr>
        <c:forEach items="${userList}" var="user">
            <tr>
                <td>${user.id}</td>
                <td>${user.username}</td>
                <td>${user.password}</td>
            </tr>
        </c:forEach>
    </table>
    <br>
    <div>当前第 ${currentPage} 页，共 ${totalPages} 页</div>

    <!-- 分页链接 -->
    <nav>
        <ul class="pagination">
            <c:forEach begin="1" end="${totalPages}" var="i">
                <c:choose>
                    <c:when test="${i == currentPage}">
                        <li class="page-item active">
                            <a class="page-link" href="#">${i}</a>
                        </li>
                    </c:when>
                    <c:otherwise>
                        <li class="page-item">
                            <a class="page-link" href="userList?page=${i}&query=${query}">${i}</a>
                        </li>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
        </ul>
    </nav>
</body>
</html>
